﻿@model AexoManager.Models.PartesViewModel

@{
    ViewBag.Title = "PartesGrid";
    Layout = "~/Views/Shared/_Template.cshtml";
}

@functions {
    object getHtmlAttributes(bool ReadOnly, string CssClass, string PlaceHolder)
    {
        if (ReadOnly)
        {
            return new { @class = CssClass, @readonly = "readonly" };
        }
        return new { @class = CssClass, @placeholder = PlaceHolder };
    }
}




@section ClientScripts {
    <script type='text/javascript'>
        $(function () {
            $("#btnNuevo").click(function () {
                $("#formPrincipal").submit();
            });

            $("#btnModificar").click(function () {
                $("#IdParte").val($("#tblPartes .active").children("td:eq(0)").text());
                $("#formPrincipal").attr("action", "@Url.Content("~/")Partes/Modificar");
                $("#formPrincipal").submit();
            });

            $("#btnEliminar").click(function () {
                if (confirm("Desea eliminar el registro seleccionado?")) {
                    $("#IdParte").val($("#tblPartes .active").children("td:eq(0)").text());
                    $("#formPrincipal").attr("action", "@Url.Content("~/")Partes/Eliminar");
                    $("#formPrincipal").submit();
                }
            });

            /*$("#tblPartes tbody tr").click(function () {
                alert($(this).children("td:eq(0)").text());
                $("#IdParte").val($(this).children("td:eq(0)").text());
            });*/


            $('#tblPartes').dataTable({
                "sDom": "<'row'<'col-sm-12'T><'col-sm-12'f>r>t<'row'<'col-sm-12'i><'col-sm-12'p>>",
                "bProcessing": true,
                "bServerSide": true,
                "sAjaxSource": "@Url.Content("~/")Partes/LoadPartes",
                "bAutoWidth": false,
                //"bDestroy": true,
                "aoColumns": [
                    { "mData": "IdParte" },
                    { "mData": "Descripcion" },
                    { "mData": "Codigo" }
                ],
                "oTableTools": {
                    "sRowSelect": "single",
                    "aButtons": [
                    ]
                }
            });
            $('.dataTables_filter input').addClass('form-control');
            $('.dataTables_length select').addClass('form-control');

        });
    </script>
}
<div id="page-content">
    <div id='wrap'>
        <div id="page-heading">
            <ol class="breadcrumb">
                <li class='active'><a href="@Url.Content("~/")Partes/">Partes</a></li>
                <li class='active'><a href="@Url.Content("~/")Partes/Index">Index</a></li>
            </ol>

            <h1>Partes</h1>
        </div>
        <div class="container">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <h4>Partes</h4>
                </div>
                @using (Html.BeginForm("Nuevo", "Partes", FormMethod.Post, new { @id = "formPrincipal", @class = "form-horizontal" }))
                {

                    <div class="panel-body collapse in">
                        <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered datatables" id="tblPartes">
                            <thead>
                                <tr>
                                    <th width="30%">IdParte</th>
                                    <th width="20%">Descripcion</th>
                                    <th width="18%">Codigo</th>
                                </tr>
                            </thead>
                            <tbody>
                                @*@foreach (var item in ViewBag.Resultado)
                                    {
                                        <tr>
                                            <td>@item.IdParte</td>
                                            <td>@item.Descripcion</td>
                                            <td>@item.Codigo</td>
                                        </tr>
                                    }*@
                            </tbody>
                        </table>
                        @Html.HiddenFor(model => model.IdParte)
                        <!--end table-->
                    </div>

                }
                <div class="panel-footer">
                    <div class="row">
                        <div class="pull-right">
                            <div class="btn-toolbar">
                                <button id="btnNuevo" class="btn-primary btn">Nuevo</button>
                                <button id="btnModificar" class="btn-primary btn">Modificar</button>
                                <button id="btnEliminar" class="btn-primary btn">Eliminar</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <!-- container -->
    </div>
    <!--wrap -->
</div>
<!-- page-content -->
